imwayland: fix potential leak of attr list
authorChristian Hergert <chergert@redhat.com>
Sat, 28 Jul 2018 17:37:21 +0000 (10:37 -0700)
committerChristian Hergert <chergert@redhat.com>
Sat, 28 Jul 2018 17:54:14 +0000 (10:54 -0700)
This fixes a potential leak of a PangoAttrList that is set when chaining
up to the parent get_preedit_string(). We check to see if the attr list
was created and reuse it instead of leaking the previous value.

gtk/gtkimcontextwayland.c

index 141ad6c6c99be005a6ea06898aac911fbbffa164..07d962891514b854c6af3d47310eefe52a0f486f 100644 (file)
@@ -469,6 +469,9 @@ gtk_im_context_wayland_get_preedit_string (GtkIMContext   *context,
   GtkIMContextWayland *context_wayland = GTK_IM_CONTEXT_WAYLAND (context);
   const char *preedit_str;
 
+  if (attrs)
+    *attrs = NULL;
+
   GTK_IM_CONTEXT_CLASS (gtk_im_context_wayland_parent_class)->get_preedit_string (context, str, attrs, cursor_pos);
 
   /* If the parent implementation returns a len>0 string, go with it */
@@ -490,7 +493,8 @@ gtk_im_context_wayland_get_preedit_string (GtkIMContext   *context,
 
   if (attrs)
     {
-      *attrs = pango_attr_list_new ();
+      if (!*attrs)
+        *attrs = pango_attr_list_new ();
       pango_attr_list_insert (*attrs,
                               pango_attr_underline_new (PANGO_UNDERLINE_SINGLE));
     }